from datetime import datetime
import sys
class logsys:
	def __init__(self, logfile):
		self.filename = logfile
		self.debug = False
	
	def log(self, logstr, type="normal"):
		if  self.debug:
			result = ""
			if type=="alerta":
				result+= "::: ALERTA ::: ", 
			elif type=="erro":
				result+= "::: ERRO ::: ",
			else:
				pass
			result+="("+str(datetime.today())+") ->" 
			result+=logstr
			print result
			f=open(self.filename, "a")
			f.writelines(result + chr(10))
			#print result
			f.close()
	# passe o caracter do arquivo e ele mostra a linha do erro
	def printinfile(self, tag, filestr, linchar):
		f = open(filestr, "r")
		e=""
		linchar=int(linchar)
		count = 0
		countln = 0
		for i in f.readlines():
			countln+=1
			i = i.replace("\n", "").replace("\r","")
			stcount = count # guarda o valor
			count += len(i)
			if count >= linchar:
				print tag + "linha " + str(countln) + " caracter " + str(linchar-stcount)
				print i
				lin=""
				for ip in range((linchar-stcount)):
					lin+= '-'
				print lin+"^"
				break
		f.close
		
if __name__ =="__main__":
	a = logsys("log.l")
	a.printinfile("Erro na ", "teste.pas", int(sys.argv[1]))
